﻿/*
 * MIT License
 *Copyright (c) 2021 咖啡与网络(java-and-net)
 *
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using CoreShop.Model;
using CoreShop.Repository;
using SqlSugar;

namespace CoreShop.Services
{
    /// <summary>
    /// 商品分类信息接口实现类
    /// </summary>
    public class corecmsdepartmentService : Repository<corecmsdepartment>, IcorecmsdepartmentService
    {
        #region 支付信息

        public bool InsertAsync(corecmsdepartment entity)
        {
            return base.Change<corecmsdepartment>().Insert(entity);
        }

        /// <summary>
        /// 更新商品分类 删除标志
        /// </summary>
        /// <param name="custo"></param>
        /// <returns></returns>
        public bool UpdDataInfo(corecmsdepartment sysPayment)
        {
            var bl = base.Update(a => new corecmsdepartment()
            {
                number = sysPayment.number,
                name = sysPayment.name,
                isDelete = sysPayment.isDelete,
            }, a => a.id == sysPayment.id);
            return bl;
        }
    

        /// <summary>
        /// 查询所有商品分类信息
        /// </summary>
        /// <returns></returns>
        public List<corecmsdepartment> SelectDataAll()
        {
            //查询出所有商品分类信息
            List<corecmsdepartment> sysPayments = new List<corecmsdepartment>();
            var where = Expressionable.Create<corecmsdepartment>();
            where = where.And(a => a.id > 0);
            sysPayments = base.AsQueryable().WhereIF(true, where.ToExpression())
                    .OrderBy(a => a.id).ToList();

            return sysPayments;
        }

        
        /// <summary>
        /// 根据商品分类编号查询商品分类信息
        /// </summary>
        /// <param name="CustoNo"></param>
        /// <returns></returns>
        public corecmsdepartment SelectDataByNumber(string number)
        {
            corecmsdepartment sysPayment = base.GetFirst(a => a.number.Contains(number));            
            return sysPayment;
        }

        /// <summary>
        /// 根据商品分类Id查询商品分类信息
        /// </summary>
        /// <param name="CustoNo"></param>
        /// <returns></returns>
        public corecmsdepartment SelectDataById(Int32 id)
        {
            corecmsdepartment sysPayment = base.GetSingle(a => a.id == id);
            return sysPayment;
        }
        #endregion
    }
}
